home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / test / except.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  2KB  |  93 lines

  1. /* Test exception handling
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet:kgorlen@alw.nih.gov
  20.  
  21. Function:
  22.     
  23. Modification History:
  24.     
  25. $Log:    except.c,v $
  26.  * Revision 3.0  90/05/20  00:29:04  kgorlen
  27.  * Release for 1st edition.
  28.  * 
  29. */
  30. static char rcsid[] = "$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/test/RCS/except.c,v 3.0 90/05/20 00:29:04 kgorlen Rel $";
  31.  
  32. #include "Exception.h"
  33. #include <stream.h>
  34.  
  35. enum exceptionCode { EXCEPTION1=1, EXCEPTION2, EXCEPTION3, EXCEPTION4 };
  36.  
  37. void x(exceptionCode n)
  38. {
  39.     BEGINX
  40.         if (n>EXCEPTION2) {
  41.             cerr << "Raising EXCEPTION" << (int) n << "...";
  42.             RAISE(n);
  43.         }
  44.         cerr << "Trying normal return from function\n";
  45.         return;
  46.     EXCEPTION
  47.         case EXCEPTION3: cerr << "EXCEPTION3 handled\n"; return;
  48.         default: cerr << "trying RAISE(EXCEPTION_CODE)...";
  49.             RAISE(EXCEPTION_CODE);
  50.     ENDX
  51. }
  52.  
  53. main()
  54. {
  55.     cerr << "Begin exception handler test\n";
  56.  
  57.     BEGINX
  58.         cerr << "Testing normal execution\n";
  59.     EXCEPTION
  60.         default: cerr << "This should not happen!\n";
  61.     ENDX
  62.  
  63.     BEGINX
  64.         cerr << "Raising EXCEPTION1...";
  65.         RAISE(EXCEPTION1);
  66.         cerr << "EXCEPTION1 not handled!\n";
  67.     EXCEPTION
  68.         case EXCEPTION1: cerr << "EXCEPTION1 handled\n";
  69.     ENDX
  70.     
  71.     BEGINX
  72.         cerr << "Testing nested exception block\n";
  73.         x(EXCEPTION2);
  74.         BEGINX
  75.             cerr << "Raising EXCEPTION2...";
  76.             RAISE(EXCEPTION2);
  77.             cerr << "EXCEPTION2 not handled!\n";
  78.         EXCEPTION
  79.             case EXCEPTION2: cerr << "EXCEPTION2 handled\n";
  80.                 cerr << "Raising EXCEPTION3...";
  81.                 x(EXCEPTION3);
  82.         ENDX
  83.         
  84.         cerr << "Raising EXCEPTION4...";
  85.         x(EXCEPTION4);
  86.         cerr << "EXCEPTION4 not handled!\n";
  87.  
  88.     EXCEPTION
  89.         default: cerr << "Test unhandled exception handler\n";
  90.             RAISE(EXCEPTION_CODE);
  91.     ENDX
  92. }
  93.